#!/bin/sh

# Define a lock file
LOCKFILE="/tmp/autostart.lock"

# Check if the lock file exists
if [ -e "$LOCKFILE" ]; then
	echo "Script autostart.sh is already running."
	exit 1
fi

# Create the lock file
touch "$LOCKFILE"

# Ensure the lock file is removed on exit
trap 'rm -f "$LOCKFILE"' EXIT

# Your script logic goes here
echo "Running the script autostart.sh"
dbus-daemon --session --address=unix:path=$XDG_CONFIG_HOME/bus &

## music player daemon-you might prefer it as a service though
mpd &

## Set background
wbg "$XDG_CONFIG_HOME/wallpaper/dwm.jpg" &

## Update contacts in Nextcloud
while true; do
	vdirsyncer sync
	sleep 600s
done &

## Check mail
while true; do
	mailsync
	sleep 60s
done &

## Clipboard manager
wl-paste --type=text --watch cliphist store &

## Disable touchpad
# thinkpad-touchpad

## Start terminal
foot -e tmux attach || foot -e tmux &

# The lock file will be removed automatically due to the trap
